﻿using inspf.Default;
using inspf.Use;
using inspf.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace inspf
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        MainViewModel vm;

        public MainWindow()
        {
            InitializeComponent();
            vm = new MainViewModel();
            Init();
            this.DataContext = vm;

            CreateFolder();
        }

        /// <summary>
        /// 创建本地缓存数据文件目录
        /// </summary>
        private void CreateFolder()
        {
            string floder = BaseConfig.url + "db";
            if (Directory.Exists(floder))
            {
                floder += "\\" + DateTime.Now.ToString("yyyy-MM-dd");
                if (!Directory.Exists(floder))
                    Directory.CreateDirectory(floder);
            }
            else
            {
                Directory.CreateDirectory(floder);
                this.CreateFolder();
            }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            ObservableCollection<AreaEntity> aeList = SetUpAreaList();

            foreach (var item in aeList)
            {
                string header = string.Format("http://{0}.58.com/shouji/0/", item.Name);
                string body = "pn{0}/?PGTID={1}&ClickID=1";
                DownLoadFile loadFile = new DownLoadFile(header + body, item.Code);
                //loadFile.EventProgressMsg += LoadFile_EventProgressMsg;
                vm.AreaModelList.Add(loadFile);
            }
        }

        /// <summary>
        /// 消息通知
        /// </summary>
        private void LoadFile_EventProgressMsg()
        {
            var amd = vm.AreaModelList.FirstOrDefault(t => t.IsRuning.Equals(false) && t.Finish.Equals(false));
            if (amd != null)
            {
                amd.Start();
            }
        }

        private ObservableCollection<AreaEntity> SetUpAreaList()
        {
            ObservableCollection<AreaEntity> areaList = new ObservableCollection<AreaEntity>();

            AreaEntity[] array = new AreaEntity[]
            {
                #region area
                
            new AreaEntity() { Code = "合肥", Name = "hf" },
            new AreaEntity() { Code = "芜湖", Name = "wuhu" },
            new AreaEntity() { Code = "蚌埠", Name = "bengbu" },
            new AreaEntity() { Code = "阜阳", Name = "fy" },
            new AreaEntity() { Code = "淮南", Name = "hn" },
            new AreaEntity() { Code = "安庆", Name = "anqing" },
            new AreaEntity() { Code = "宿州", Name = "suzhou" },
            new AreaEntity() { Code = "六安", Name = "la" },
            new AreaEntity() { Code = "淮北", Name = "huaibei" },
            new AreaEntity() { Code = "滁州", Name = "chuzhou" },
            new AreaEntity() { Code = "马鞍山", Name = "mas" },
            new AreaEntity() { Code = "铜陵", Name = "tongling" },
            new AreaEntity() { Code = "宣城", Name = "xuancheng" },
            new AreaEntity() { Code = "亳州", Name = "bozhou" },
            new AreaEntity() { Code = "黄山", Name = "huangshan" },
            new AreaEntity() { Code = "池州", Name = "chizhou" },
            new AreaEntity() { Code = "巢湖", Name = "ch" },
            new AreaEntity() { Code = "和县", Name = "hexian" },
            new AreaEntity() { Code = "霍邱", Name = "hq" },
            new AreaEntity() { Code = "桐城", Name = "tongcheng" },
            new AreaEntity() { Code = "宁国", Name = "ningguo" },
            new AreaEntity() { Code = "天长", Name = "tianchang" },
            new AreaEntity() { Code = "福州", Name = "fz" },
            new AreaEntity() { Code = "厦门", Name = "xm" },
            new AreaEntity() { Code = "泉州", Name = "qz" },
            new AreaEntity() { Code = "莆田", Name = "pt" },
            new AreaEntity() { Code = "漳州", Name = "zhangzhou" },
            new AreaEntity() { Code = "宁德", Name = "nd" },
            new AreaEntity() { Code = "三明", Name = "sm" },
            new AreaEntity() { Code = "南平", Name = "np" },
            new AreaEntity() { Code = "龙岩", Name = "ly" },
            new AreaEntity() { Code = "武夷山", Name = "wuyishan" },
            new AreaEntity() { Code = "石狮", Name = "shishi" },
            new AreaEntity() { Code = "晋江", Name = "jinjiangshi" },
            new AreaEntity() { Code = "南安", Name = "nananshi" },
            new AreaEntity() { Code = "龙海", Name = "longhai" },
            new AreaEntity() { Code = "深圳", Name = "sz" },
            new AreaEntity() { Code = "广州", Name = "gz" },
            new AreaEntity() { Code = "东莞", Name = "dg" },
            new AreaEntity() { Code = "佛山", Name = "fs" },
            new AreaEntity() { Code = "中山", Name = "zs" },
            new AreaEntity() { Code = "珠海", Name = "zh" },
            new AreaEntity() { Code = "惠州", Name = "huizhou" },
            new AreaEntity() { Code = "江门", Name = "jm" },
            new AreaEntity() { Code = "汕头", Name = "st" },
            new AreaEntity() { Code = "湛江", Name = "zhanjiang" },
            new AreaEntity() { Code = "肇庆", Name = "zq" },
            new AreaEntity() { Code = "茂名", Name = "mm" },
            new AreaEntity() { Code = "揭阳", Name = "jy" },
            new AreaEntity() { Code = "梅州", Name = "mz" },
            new AreaEntity() { Code = "清远", Name = "qingyuan" },
            new AreaEntity() { Code = "阳江", Name = "yj" },
            new AreaEntity() { Code = "韶关", Name = "sg" },
            new AreaEntity() { Code = "河源", Name = "heyuan" },
            new AreaEntity() { Code = "云浮", Name = "yf" },
            new AreaEntity() { Code = "汕尾", Name = "sw" },
            new AreaEntity() { Code = "潮州", Name = "chaozhou" },
            new AreaEntity() { Code = "台山", Name = "taishan" },
            new AreaEntity() { Code = "阳春", Name = "yangchun" },
            new AreaEntity() { Code = "顺德", Name = "sd" },
            new AreaEntity() { Code = "惠东", Name = "huidong" },
            new AreaEntity() { Code = "博罗", Name = "boluo" },
            new AreaEntity() { Code = "海丰", Name = "haifengxian" },
            new AreaEntity() { Code = "南宁", Name = "nn" },
            new AreaEntity() { Code = "柳州", Name = "liuzhou" },
            new AreaEntity() { Code = "桂林", Name = "gl" },
            new AreaEntity() { Code = "玉林", Name = "yulin" },
            new AreaEntity() { Code = "梧州", Name = "wuzhou" },
            new AreaEntity() { Code = "北海", Name = "bh" },
            new AreaEntity() { Code = "贵港", Name = "gg" },
            new AreaEntity() { Code = "钦州", Name = "qinzhou" },
            new AreaEntity() { Code = "百色", Name = "baise" },
            new AreaEntity() { Code = "河池", Name = "hc" },
            new AreaEntity() { Code = "来宾", Name = "lb" },
            new AreaEntity() { Code = "贺州", Name = "hezhou" },
            new AreaEntity() { Code = "防城港", Name = "fcg" },
            new AreaEntity() { Code = "崇左", Name = "chongzuo" },
            new AreaEntity() { Code = "贵阳", Name = "gy" },
            new AreaEntity() { Code = "遵义", Name = "zunyi" },
            new AreaEntity() { Code = "黔东南", Name = "qdn" },
            new AreaEntity() { Code = "黔南", Name = "qn" },
            new AreaEntity() { Code = "六盘水", Name = "lps" },
            new AreaEntity() { Code = "毕节", Name = "bijie" },
            new AreaEntity() { Code = "铜仁", Name = "tr" },
            new AreaEntity() { Code = "安顺", Name = "anshun" },
            new AreaEntity() { Code = "黔西南", Name = "qxn" },
            new AreaEntity() { Code = "仁怀市", Name = "renhuaishi" },
            new AreaEntity() { Code = "兰州", Name = "lz" },
            new AreaEntity() { Code = "天水", Name = "tianshui" },
            new AreaEntity() { Code = "白银", Name = "by" },
            new AreaEntity() { Code = "庆阳", Name = "qingyang" },
            new AreaEntity() { Code = "平凉", Name = "pl" },
            new AreaEntity() { Code = "酒泉", Name = "jq" },
            new AreaEntity() { Code = "张掖", Name = "zhangye" },
            new AreaEntity() { Code = "武威", Name = "wuwei" },
            new AreaEntity() { Code = "定西", Name = "dx" },
            new AreaEntity() { Code = "金昌", Name = "jinchang" },
            new AreaEntity() { Code = "陇南", Name = "ln" },
            new AreaEntity() { Code = "临夏", Name = "linxia" },
            new AreaEntity() { Code = "嘉峪关", Name = "jyg" },
            new AreaEntity() { Code = "甘南", Name = "gn" },
            new AreaEntity() { Code = "海口", Name = "haikou" },
            new AreaEntity() { Code = "三亚", Name = "sanya" },
            new AreaEntity() { Code = "五指山", Name = "wzs" },
            new AreaEntity() { Code = "三沙", Name = "sansha" },
            new AreaEntity() { Code = "万宁", Name = "wanning" },
            new AreaEntity() { Code = "文昌", Name = "wenchang" },
            new AreaEntity() { Code = "屯昌", Name = "tunchang" },
            new AreaEntity() { Code = "琼中", Name = "qiongzhong" },
            new AreaEntity() { Code = "陵水", Name = "lingshui" },
            new AreaEntity() { Code = "东方", Name = "df" },
            new AreaEntity() { Code = "定安", Name = "da" },
            new AreaEntity() { Code = "澄迈", Name = "cm" },
            new AreaEntity() { Code = "保亭", Name = "baoting" },
            new AreaEntity() { Code = "白沙", Name = "baish" },
            new AreaEntity() { Code = "儋州", Name = "danzhou" },
            new AreaEntity() { Code = "郑州", Name = "zz" },
            new AreaEntity() { Code = "洛阳", Name = "luoyang" },
            new AreaEntity() { Code = "新乡", Name = "xx" },
            new AreaEntity() { Code = "南阳", Name = "ny" },
            new AreaEntity() { Code = "许昌", Name = "xc" },
            new AreaEntity() { Code = "平顶山", Name = "pds" },
            new AreaEntity() { Code = "安阳", Name = "ay" },
            new AreaEntity() { Code = "焦作", Name = "jiaozuo" },
            new AreaEntity() { Code = "商丘", Name = "sq" },
            new AreaEntity() { Code = "开封", Name = "kaifeng" },
            new AreaEntity() { Code = "濮阳", Name = "puyang" },
            new AreaEntity() { Code="周口",Name="zk" },
            new AreaEntity() { Code="信阳",Name="xy" },
            new AreaEntity() { Code="驻马店",Name="zmd" },
            new AreaEntity() { Code="漯河",Name="luohe" },
            new AreaEntity() { Code="三门峡",Name="smx" },
            new AreaEntity() { Code="鹤壁",Name="hb" },
            new AreaEntity() { Code="济源",Name="jiyuan" },
            new AreaEntity() { Code="明港",Name="mg" },
            new AreaEntity() { Code="鄢陵",Name="yanling" },
            new AreaEntity() { Code="禹州",Name="yuzhou" },
            new AreaEntity() { Code="长葛",Name="changge" },
            new AreaEntity() { Code="灵宝",Name="lingbaoshi" },
            new AreaEntity() { Code="杞县",Name="qixianqu" },
            new AreaEntity() { Code="汝州",Name="ruzhou" },
            new AreaEntity() { Code="项城",Name="xiangchengshi" },
            new AreaEntity() { Code= "偃师", Name= "yanshiqu" },
            new AreaEntity() { Code= "长垣", Name= "changyuan" },
            new AreaEntity() { Code="哈尔滨",Name="hrb" },
            new AreaEntity() { Code="大庆",Name="dq" },
            new AreaEntity() { Code="齐齐哈尔",Name="qqhr" },
            new AreaEntity() { Code="牡丹江",Name="mdj" },
            new AreaEntity() { Code="绥化",Name="suihua" },
            new AreaEntity() { Code="佳木斯",Name="jms" },
            new AreaEntity() { Code="鸡西",Name="jixi" },
            new AreaEntity() { Code="双鸭山",Name="sys" },
            new AreaEntity() { Code="鹤岗",Name="hegang" },
            new AreaEntity() { Code="黑河",Name="heihe" },
            new AreaEntity() { Code="伊春",Name="yich" },
            new AreaEntity() { Code="七台河",Name="qth" },
            new AreaEntity() { Code="大兴安岭",Name="dxal" },
            new AreaEntity() {Code="武汉",Name="wh" },
            new AreaEntity() {Code="宜昌",Name="yc" },
            new AreaEntity() {Code="襄阳",Name="xf" },
            new AreaEntity() {Code="荆州",Name="jingzhou" },
            new AreaEntity() {Code="十堰",Name="shiyan" },
            new AreaEntity() {Code="黄石",Name="hshi" },
            new AreaEntity() {Code="孝感",Name="xiaogan" },
            new AreaEntity() {Code="黄冈",Name="hg" },
            new AreaEntity() {Code="恩施",Name="es" },
            new AreaEntity() {Code="荆门",Name="jingmen" },
            new AreaEntity() {Code="咸宁",Name="xianning" },
            new AreaEntity() {Code="鄂州",Name="ez" },
            new AreaEntity() {Code="随州",Name="suizhou" },
            new AreaEntity() {Code="潜江",Name="qianjiang" },
            new AreaEntity() {Code="天门",Name="tm" },
            new AreaEntity() {Code="仙桃",Name="xiantao" },
            new AreaEntity() {Code="神农架",Name="snj" },
            new AreaEntity() {Code="宜都",Name="yidou" },
            new AreaEntity() {Code="汉川",Name="hanchuan" },
            new AreaEntity() {Code="枣阳",Name="zaoyang" },
            new AreaEntity() {Code="长沙",Name="cs" },
            new AreaEntity() {Code="株洲",Name="zhuzhou" },
            new AreaEntity() {Code="益阳",Name="yiyang" },
            new AreaEntity() {Code="常德",Name="changde" },
            new AreaEntity() {Code="衡阳",Name="hy" },
            new AreaEntity() {Code="湘潭",Name="xiangtan" },
            new AreaEntity() {Code="岳阳",Name="yy" },
            new AreaEntity() {Code="郴州",Name="chenzhou" },
            new AreaEntity() {Code="邵阳",Name="shaoyang" },
            new AreaEntity() {Code="怀化",Name="hh" },
            new AreaEntity() {Code="永州",Name="yongzhou" },
            new AreaEntity() {Code="娄底",Name="ld" },
            new AreaEntity() {Code="湘西",Name="xiangxi" },
            new AreaEntity() {Code="张家界",Name="zjj" },
            new AreaEntity() {Code="醴陵",Name="liling" },
            new AreaEntity() {Code="石家庄",Name="sjz" },
            new AreaEntity() {Code="保定",Name="bd" },
            new AreaEntity() {Code="唐山",Name="ts" },
            new AreaEntity() {Code="廊坊",Name="lf" },
            new AreaEntity() {Code="邯郸",Name="hd" },
            new AreaEntity() {Code="秦皇岛",Name="qhd" },
            new AreaEntity() {Code="沧州",Name="cangzhou" },
            new AreaEntity() {Code="邢台",Name="xt" },
            new AreaEntity() {Code="衡水",Name="hs" },
            new AreaEntity() {Code="张家口",Name="zjk" },
            new AreaEntity() {Code="承德",Name="chengde" },
            new AreaEntity() {Code="定州",Name="dingzhou" },
            new AreaEntity() {Code="馆陶",Name="gt" },
            new AreaEntity() {Code="张北",Name="zhangbei" },
            new AreaEntity() {Code="赵县",Name="zx" },
            new AreaEntity() {Code="正定",Name="zd" },
            new AreaEntity() {Code="迁安市",Name="qianan" },
            new AreaEntity() {Code="任丘",Name="renqiu" },
            new AreaEntity() {Code="三河",Name="sanhe" },
            new AreaEntity() {Code="武安",Name="wuan" },
            new AreaEntity() {Code="雄安新区",Name="xionganxinqu" },
            new AreaEntity() {Code="燕郊",Name="lfyanjiao" },
            new AreaEntity() {Code="涿州",Name="zhuozhou" },
            new AreaEntity() {Code="苏州",Name="su" },
            new AreaEntity() {Code="南京",Name="nj" },
            new AreaEntity() {Code="无锡",Name="wx" },
            new AreaEntity() {Code="常州",Name="cz" },
            new AreaEntity() {Code="徐州",Name="xz" },
            new AreaEntity() {Code="南通",Name="nt" },
            new AreaEntity() {Code="扬州",Name="yz" },
            new AreaEntity() {Code="盐城",Name="yancheng" },
            new AreaEntity() {Code="淮安",Name="ha" },
            new AreaEntity() {Code="连云港",Name="lyg" },
            new AreaEntity() {Code="泰州",Name="taizhou" },
            new AreaEntity() {Code="宿迁",Name="suqian" },
            new AreaEntity() {Code="镇江",Name="zj" },
            new AreaEntity() {Code="沭阳",Name="shuyang" },
            new AreaEntity() {Code="大丰",Name="dafeng" },
            new AreaEntity() {Code="如皋",Name="rugao" },
            new AreaEntity() {Code="启东",Name="qidong" },
            new AreaEntity() {Code="溧阳",Name="liyang" },
            new AreaEntity() {Code="海门",Name="haimen" },
            new AreaEntity() {Code="东海",Name="donghai" },
            new AreaEntity() {Code="扬中",Name="yangzhong" },
            new AreaEntity() {Code="兴化",Name="xinghuashi" },
            new AreaEntity() {Code="新沂",Name="xinyishi" },
            new AreaEntity() {Code="泰兴",Name="taixing" },
            new AreaEntity() {Code="如东",Name="rudong" },
            new AreaEntity() {Code="邳州",Name="pizhou" },
            new AreaEntity() {Code="沛县",Name="xzpeixian" },
            new AreaEntity() {Code="靖江",Name="jingjiang" },
            new AreaEntity() {Code="建湖",Name="jianhu" },
            new AreaEntity() {Code="海安",Name="haian" },
            new AreaEntity() {Code="东台",Name="dongtai" },
            new AreaEntity() {Code="丹阳",Name="danyang" },
            new AreaEntity() {Code="宝应县",Name="baoyingx" },
            new AreaEntity() {Code="灌南",Name="guannan" },
            new AreaEntity() {Code="灌云",Name="guanyun" },
            new AreaEntity() {Code="姜堰",Name="jiangyan" },
            new AreaEntity() {Code="金坛",Name="jintan" },
            new AreaEntity() {Code="昆山",Name="szkunshan" },
            new AreaEntity() {Code="泗洪",Name="sihong" },
            new AreaEntity() {Code="泗阳",Name="siyang" },
            new AreaEntity() {Code="南昌",Name="nc" },
            new AreaEntity() {Code="赣州",Name="ganzhou" },
            new AreaEntity() {Code="九江",Name="jj" },
            new AreaEntity() {Code="宜春",Name="yichun" },
            new AreaEntity() {Code="吉安",Name="ja" },
            new AreaEntity() {Code="上饶",Name="sr" },
            new AreaEntity() {Code="萍乡",Name="px" },
            new AreaEntity() {Code="抚州",Name="fuzhou" },
            new AreaEntity() {Code="景德镇",Name="jdz" },
            new AreaEntity() {Code="新余",Name="xinyu" },
            new AreaEntity() {Code="鹰潭",Name="yingtan" },
            new AreaEntity() {Code="永新",Name="yxx" },
            new AreaEntity() {Code="乐平",Name="lepingshi" },
            new AreaEntity() {Code="长春",Name="cc" },
            new AreaEntity() {Code="吉林",Name="jl" },
            new AreaEntity() {Code="四平",Name="sp" },
            new AreaEntity() {Code="延边",Name="yanbian" },
            new AreaEntity() {Code="松原",Name="songyuan" },
            new AreaEntity() {Code="白城",Name="bc" },
            new AreaEntity() {Code="通化",Name="th" },
            new AreaEntity() {Code="白山",Name="baishan" },
            new AreaEntity() {Code="辽源",Name="liaoyuan" },
            new AreaEntity() {Code="公主岭",Name="gongzhuling" },
            new AreaEntity() {Code="沈阳",Name="sy" },
            new AreaEntity() {Code="大连",Name="dl" },
            new AreaEntity() {Code="鞍山",Name="as" },
            new AreaEntity() {Code="锦州",Name="jinzhou" },
            new AreaEntity() {Code="抚顺",Name="fushun" },
            new AreaEntity() {Code="营口",Name="yk" },
            new AreaEntity() {Code="盘锦",Name="pj" },
            new AreaEntity() {Code="朝阳",Name="cy" },
            new AreaEntity() {Code="丹东",Name="dandong" },
            new AreaEntity() {Code="辽阳",Name="liaoyang" },
            new AreaEntity() {Code="本溪",Name="benxi" },
            new AreaEntity() {Code="葫芦岛",Name="hld" },
            new AreaEntity() {Code="铁岭",Name="tl" },
            new AreaEntity() {Code="阜新",Name="fx" },
            new AreaEntity() {Code="庄河",Name="pld" },
            new AreaEntity() {Code="瓦房店",Name="wfd" },
            new AreaEntity() {Code="银川",Name="yinchuan" },
            new AreaEntity() {Code="吴忠",Name="wuzhong" },
            new AreaEntity() {Code="石嘴山",Name="szs" },
            new AreaEntity() {Code="中卫",Name="zw" },
            new AreaEntity() {Code="固原",Name="guyuan" },
            new AreaEntity() {Code="呼和浩特",Name="hu" },
            new AreaEntity() {Code="包头",Name="bt" },
            new AreaEntity() {Code="赤峰",Name="chifeng" },
            new AreaEntity() {Code="鄂尔多斯",Name="erds" },
            new AreaEntity() {Code="通辽",Name="tongliao" },
            new AreaEntity() {Code="呼伦贝尔",Name="hlbe" },
            new AreaEntity() {Code="巴彦淖尔市",Name="bycem" },
            new AreaEntity() {Code="乌兰察布",Name="wlcb" },
            new AreaEntity() {Code="锡林郭勒",Name="xl" },
            new AreaEntity() {Code="兴安盟",Name="xam" },
            new AreaEntity() {Code="乌海",Name="wuhai" },
            new AreaEntity() {Code="阿拉善盟",Name="alsm" },
            new AreaEntity() {Code="海拉尔",Name="hlr" },
            new AreaEntity() {Code="西宁",Name="xn" },
            new AreaEntity() {Code="海西",Name="hx" },
            new AreaEntity() {Code="海北",Name="haibei" },
            new AreaEntity() {Code="果洛",Name="guoluo" },
            new AreaEntity() {Code="海东",Name="haidong" },
            new AreaEntity() {Code="黄南",Name="huangnan" },
            new AreaEntity() {Code="玉树",Name="ys" },
            new AreaEntity() {Code="海南",Name="hainan" },
            new AreaEntity() {Code="青岛",Name="qd" },
            new AreaEntity() {Code="济南",Name="jn" },
            new AreaEntity() {Code="烟台",Name="yt" },
            new AreaEntity() {Code="潍坊",Name="wf" },
            new AreaEntity() {Code="临沂",Name="linyi" },
            new AreaEntity() {Code="淄博",Name="zb" },
            new AreaEntity() {Code="济宁",Name="jining" },
            new AreaEntity() {Code="泰安",Name="ta" },
            new AreaEntity() {Code="聊城",Name="lc" },
            new AreaEntity() {Code="威海",Name="weihai" },
            new AreaEntity() {Code="枣庄",Name="zaozhuang" },
            new AreaEntity() {Code="德州",Name="dz" },
            new AreaEntity() {Code="日照",Name="rizhao" },
            new AreaEntity() {Code="东营",Name="dy" },
            new AreaEntity() {Code="菏泽",Name="heze" },
            new AreaEntity() {Code="滨州",Name="bz" },
            new AreaEntity() {Code="莱芜",Name="lw" },
            new AreaEntity() {Code="章丘",Name="zhangqiu" },
            new AreaEntity() {Code="垦利",Name="kl" },
            new AreaEntity() {Code="诸城",Name="zc" },
            new AreaEntity() {Code="寿光",Name="shouguang" },
            new AreaEntity() {Code="龙口",Name="longkou" },
            new AreaEntity() {Code="曹县",Name="caoxian" },
            new AreaEntity() {Code="单县",Name="shanxian" },
            new AreaEntity() {Code="肥城",Name="feicheng" },
            new AreaEntity() {Code="高密",Name="gaomi" },
            new AreaEntity() {Code="广饶",Name="guangrao" },
            new AreaEntity() {Code="桓台",Name="huantaixian" },
            new AreaEntity() {Code="莒县",Name="juxian" },
            new AreaEntity() {Code="莱州",Name="laizhou" },
            new AreaEntity() {Code="蓬莱",Name="penglai" },
            new AreaEntity() {Code="青州",Name="qingzhou" },
            new AreaEntity() {Code="荣成",Name="rongcheng" },
            new AreaEntity() {Code="乳山",Name="rushan" },
            new AreaEntity() {Code="滕州",Name="tengzhou" },
            new AreaEntity() {Code="新泰",Name="xintai" },
            new AreaEntity() {Code="招远",Name="zhaoyuan" },
            new AreaEntity() {Code="邹城",Name="zoucheng" },
            new AreaEntity() {Code="邹平",Name="zouping" },
            new AreaEntity() {Code="太原",Name="ty" },
            new AreaEntity() {Code="临汾",Name="linfen" },
            new AreaEntity() {Code="大同",Name="dt" },
            new AreaEntity() {Code="运城",Name="yuncheng" },
            new AreaEntity() {Code="晋中",Name="jz" },
            new AreaEntity() {Code="长治",Name="changzhi" },
            new AreaEntity() {Code="晋城",Name="jincheng" },
            new AreaEntity() {Code="阳泉",Name="yq" },
            new AreaEntity() {Code="吕梁",Name="lvliang" },
            new AreaEntity() {Code="忻州",Name="xinzhou" },
            new AreaEntity() {Code="朔州",Name="shuozhou" },
            new AreaEntity() {Code="临猗",Name="linyixian" },
            new AreaEntity() {Code="清徐",Name="qingxu" },
            new AreaEntity() {Code="西安",Name="xa" },
            new AreaEntity() {Code="咸阳",Name="xianyang" },
            new AreaEntity() {Code="宝鸡",Name="baoji" },
            new AreaEntity() {Code="渭南",Name="wn" },
            new AreaEntity() {Code="汉中",Name="hanzhong" },
            new AreaEntity() {Code="榆林",Name="yl" },
            new AreaEntity() {Code="延安",Name="yanan" },
            new AreaEntity() {Code="安康",Name="ankang" },
            new AreaEntity() {Code="商洛",Name="sl" },
            new AreaEntity() {Code="铜川",Name="tc" },
            new AreaEntity() {Code="神木",Name="shenmu" },
            new AreaEntity() {Code="成都",Name="cd" },
            new AreaEntity() {Code="绵阳",Name="mianyang" },
            new AreaEntity() {Code="德阳",Name="deyang" },
            new AreaEntity() {Code="南充",Name="nanchong" },
            new AreaEntity() {Code="宜宾",Name="yb" },
            new AreaEntity() {Code="自贡",Name="zg" },
            new AreaEntity() {Code="乐山",Name="ls" },
            new AreaEntity() {Code="泸州",Name="luzhou" },
            new AreaEntity() {Code="达州",Name="dazhou" },
            new AreaEntity() {Code="内江",Name="scnj" },
            new AreaEntity() {Code="榆林",Name="yl" },
            new AreaEntity() {Code="延安",Name="yanan" },
            new AreaEntity() {Code="安康",Name="ankang" },
            new AreaEntity() {Code="商洛",Name="sl" },
            new AreaEntity() {Code="铜川",Name="tc" },
            new AreaEntity() {Code="神木",Name="shenmu" },
            new AreaEntity() {Code="成都",Name="cd" },
            new AreaEntity() {Code="绵阳",Name="mianyang" },
            new AreaEntity() {Code="德阳",Name="deyang" },
            new AreaEntity() {Code="南充",Name="nanchong" },
            new AreaEntity() {Code="宜宾",Name="yb" },
            new AreaEntity() {Code="自贡",Name="zg" },
            new AreaEntity() {Code="乐山",Name="ls" },
            new AreaEntity() {Code="泸州",Name="luzhou" },
            new AreaEntity() {Code="达州",Name="dazhou" },
            new AreaEntity() {Code="内江",Name="scnj" },
            new AreaEntity() {Code="遂宁",Name="suining" },
            new AreaEntity() {Code="攀枝花",Name="panzhihua" },
            new AreaEntity() {Code="眉山",Name="ms" },
            new AreaEntity() {Code="广安",Name="ga" },
            new AreaEntity() {Code="资阳",Name="zy" },
            new AreaEntity() {Code="凉山",Name="liangshan" },
            new AreaEntity() {Code="广元",Name="guangyuan" },
            new AreaEntity() {Code="雅安",Name="ya" },
            new AreaEntity() {Code="巴中",Name="bazhong" },
            new AreaEntity() {Code="阿坝",Name="ab" },
            new AreaEntity() {Code="甘孜",Name="ganzi" },
            new AreaEntity() {Code="安岳",Name="anyuexian" },
            new AreaEntity() {Code="广汉",Name="guanghanshi" },
            new AreaEntity() {Code="简阳",Name="jianyangshi" },
            new AreaEntity() {Code="仁寿",Name="renshouxian" },
            new AreaEntity() {Code="乌鲁木齐",Name="xj" },
            new AreaEntity() {Code="昌吉",Name="changji" },
            new AreaEntity() {Code="巴音郭楞",Name="bygl" },
            new AreaEntity() {Code="伊犁",Name="ks" },
            new AreaEntity() {Code="阿克苏",Name="aks" },
            new AreaEntity() {Code="喀什",Name="ks" },
            new AreaEntity() {Code="哈密",Name="hami" },
            new AreaEntity() {Code="克拉玛依",Name="klmy" },
            new AreaEntity() {Code="博尔塔拉",Name="betl" },
            new AreaEntity() {Code="吐鲁番",Name="tlf" },
            new AreaEntity() {Code="和田",Name="ht" },
            new AreaEntity() {Code="石河子",Name="shz" },
            new AreaEntity() {Code="克孜勒苏",Name="kzls" },
            new AreaEntity() {Code="阿拉尔",Name="ale" },
            new AreaEntity() {Code="五家渠",Name="wjq" },
            new AreaEntity() {Code="图木舒克",Name="tmsk" },
            new AreaEntity() {Code="库尔勒",Name="kel" },
            new AreaEntity() {Code="阿勒泰",Name="alt" },
            new AreaEntity() {Code="塔城",Name="tac" },
            new AreaEntity() {Code="拉萨",Name="lasa" },
            new AreaEntity() {Code="日喀则",Name="rkz" },
            new AreaEntity() {Code="山南",Name="sn" },
            new AreaEntity() {Code="林芝",Name="linzhi" },
            new AreaEntity() {Code="昌都",Name="changdu" },
            new AreaEntity() {Code="那曲",Name="nq" },
            new AreaEntity() {Code="阿里",Name="al" },
            new AreaEntity() {Code="日土",Name="rituxian" },
            new AreaEntity() {Code="改则",Name="gaizexian" },
            new AreaEntity() {Code="昆明",Name="km" },
            new AreaEntity() {Code="曲靖",Name="qj" },
            new AreaEntity() {Code="大理",Name="dali" },
            new AreaEntity() {Code="红河",Name="honghe" },
            new AreaEntity() {Code="玉溪",Name="yx" },
            new AreaEntity() {Code="丽江",Name="lj" },
            new AreaEntity() {Code="文山",Name="ws" },
            new AreaEntity() {Code="楚雄",Name="cx" },
            new AreaEntity() {Code="西双版纳",Name="bn" },
            new AreaEntity() {Code="昭通",Name="zt" },
            new AreaEntity() {Code="德宏",Name="dh" },
            new AreaEntity() {Code="普洱",Name="pe" },
            new AreaEntity() {Code="保山",Name="bs" },
            new AreaEntity() {Code="临沧",Name="lincang" },
            new AreaEntity() {Code="迪庆",Name="diqing" },
            new AreaEntity() {Code="怒江",Name="nujiang" },
            new AreaEntity() {Code="杭州",Name="hz" },
            new AreaEntity() {Code="宁波",Name="nb" },
            new AreaEntity() {Code="温州",Name="wz" },
            new AreaEntity() {Code="金华",Name="jh" },
            new AreaEntity() {Code="嘉兴",Name="jx" },
            new AreaEntity() {Code="台州",Name="tz" },
            new AreaEntity() {Code="绍兴",Name="sx" },
            new AreaEntity() {Code="湖州",Name="huzhou" },
            new AreaEntity() {Code="丽水",Name="lishui" },
            new AreaEntity() {Code="衢州",Name="quzhou" },
            new AreaEntity() {Code="舟山",Name="zhoushan" },
            new AreaEntity() {Code="乐清",Name="yueqingcity" },
            new AreaEntity() {Code="瑞安",Name="ruiancity" },
            new AreaEntity() {Code="义乌",Name="yiwu" },
            new AreaEntity() {Code="余姚",Name="yuyao" },
            new AreaEntity() {Code="诸暨",Name="zhuji" },
            new AreaEntity() {Code="象山",Name="xiangshanxian" },
            new AreaEntity() {Code="温岭",Name="wenling" },
            new AreaEntity() {Code="桐乡",Name="tongxiang" },
            new AreaEntity() {Code="慈溪",Name="cixi" },
            new AreaEntity() {Code="长兴",Name="changxing" },
            new AreaEntity() {Code="嘉善",Name="jiashanx" },
            new AreaEntity() {Code="海宁",Name="haining" },
            new AreaEntity() {Code="德清",Name="deqing" },
            new AreaEntity() {Code="东阳",Name="dongyang" },
            new AreaEntity() {Code="安吉",Name="anji" },
            new AreaEntity() {Code="苍南",Name="cangnanxian" },
            new AreaEntity() {Code="临海",Name="linhai" },
            new AreaEntity() {Code="永康",Name="yongkang" },
            new AreaEntity() {Code="玉环",Name="yuhuan" },
            new AreaEntity() {Code="香港",Name="hk" },
            new AreaEntity() {Code="澳门",Name="am" },
            new AreaEntity() {Code="台湾",Name="tw" },
            new AreaEntity() {Code="其他",Name="cn" }

            #endregion
            };

            foreach (var item in array.ToArray())
                areaList.Add(item);
            return areaList;
        }
        
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            foreach (var item in vm.AreaModelList)
            {
                await item.Start();
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            foreach (var item in vm.AreaModelList)
            {
                item.SaveChangeds();
            }
        }
    }
}
